﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Himp.Outpatient.Migrations
{
    /// <inheritdoc />
    public partial class add_table_OtpOrd : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "OtpOrd",
                schema: "Outpatient",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    OrdBizSouc = table.Column<int>(type: "integer", nullable: false),
                    OrdNo = table.Column<string>(type: "text", nullable: false),
                    Invono = table.Column<string>(type: "text", nullable: true),
                    OrdName = table.Column<string>(type: "text", nullable: false),
                    OrdExp = table.Column<string>(type: "text", nullable: false),
                    InvoAmt = table.Column<decimal>(type: "numeric", nullable: false),
                    TotAmt = table.Column<decimal>(type: "numeric", nullable: false),
                    DiscAmt = table.Column<decimal>(type: "numeric", nullable: false),
                    RecAmt = table.Column<decimal>(type: "numeric", nullable: false),
                    RecdAmt = table.Column<decimal>(type: "numeric", nullable: false),
                    OrdStas = table.Column<int>(type: "integer", nullable: false),
                    Fintime = table.Column<DateTime>(type: "timestamp without time zone", nullable: true),
                    Cncltime = table.Column<DateTime>(type: "timestamp without time zone", nullable: true),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true),
                    ExtraProperties = table.Column<string>(type: "text", nullable: false),
                    ConcurrencyStamp = table.Column<string>(type: "character varying(40)", maxLength: 40, nullable: false),
                    CreationTime = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uuid", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "timestamp without time zone", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_OtpOrd", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "OtpPayWay",
                schema: "Outpatient",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    PayWayCodg = table.Column<string>(type: "text", nullable: false),
                    PayWayName = table.Column<string>(type: "text", nullable: false),
                    Icon = table.Column<string>(type: "text", nullable: false),
                    SrtNo = table.Column<int>(type: "integer", nullable: false),
                    ValiFlag = table.Column<bool>(type: "boolean", nullable: false),
                    DefFlag = table.Column<bool>(type: "boolean", nullable: false),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false),
                    ExtraProperties = table.Column<string>(type: "text", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_OtpPayWay", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "OtpOrdDetl",
                schema: "Outpatient",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    ChrgitmTypeCodg = table.Column<string>(type: "text", nullable: false),
                    ChrgitmTypeName = table.Column<string>(type: "text", nullable: false),
                    PubItemCodg = table.Column<string>(type: "text", nullable: false),
                    PubItemName = table.Column<string>(type: "text", nullable: false),
                    Pric = table.Column<decimal>(type: "numeric", nullable: false),
                    DiscRate = table.Column<decimal>(type: "numeric", nullable: false),
                    Cnt = table.Column<decimal>(type: "numeric", nullable: false),
                    Amt = table.Column<decimal>(type: "numeric", nullable: false),
                    OrdInfoId = table.Column<Guid>(type: "uuid", nullable: false),
                    ExtraProperties = table.Column<string>(type: "text", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_OtpOrdDetl", x => x.Id);
                    table.ForeignKey(
                        name: "FK_OtpOrdDetl_OtpOrd_OrdInfoId",
                        column: x => x.OrdInfoId,
                        principalSchema: "Outpatient",
                        principalTable: "OtpOrd",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "OtpOrdFeeDetl",
                schema: "Outpatient",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    ChrgitmTypeCodg = table.Column<string>(type: "text", nullable: false),
                    ChrgitmTypeName = table.Column<string>(type: "text", nullable: false),
                    ChrgitmTypeGrpCode = table.Column<string>(type: "text", nullable: false),
                    ChrgitmTypeGrpName = table.Column<string>(type: "text", nullable: false),
                    Amt = table.Column<decimal>(type: "numeric", nullable: false),
                    OrdInfoId = table.Column<Guid>(type: "uuid", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_OtpOrdFeeDetl", x => x.Id);
                    table.ForeignKey(
                        name: "FK_OtpOrdFeeDetl_OtpOrd_OrdInfoId",
                        column: x => x.OrdInfoId,
                        principalSchema: "Outpatient",
                        principalTable: "OtpOrd",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "OtpPayRec",
                schema: "Outpatient",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    PayWayId = table.Column<Guid>(type: "uuid", nullable: false),
                    TraceSn = table.Column<string>(type: "text", nullable: false),
                    Amt = table.Column<decimal>(type: "numeric", nullable: false),
                    PayTime = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
                    RefdTime = table.Column<DateTime>(type: "timestamp without time zone", nullable: true),
                    RefdSn = table.Column<string>(type: "text", nullable: true),
                    PayRecStas = table.Column<int>(type: "integer", nullable: false),
                    PayOpterCodg = table.Column<string>(type: "text", nullable: false),
                    PayOpterName = table.Column<string>(type: "text", nullable: false),
                    RefdOpterCodg = table.Column<string>(type: "text", nullable: true),
                    RefdOpterName = table.Column<string>(type: "text", nullable: true),
                    OrdInfoId = table.Column<Guid>(type: "uuid", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true),
                    ExtraProperties = table.Column<string>(type: "text", nullable: false),
                    ConcurrencyStamp = table.Column<string>(type: "character varying(40)", maxLength: 40, nullable: false),
                    CreationTime = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uuid", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "timestamp without time zone", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_OtpPayRec", x => x.Id);
                    table.ForeignKey(
                        name: "FK_OtpPayRec_OtpOrd_OrdInfoId",
                        column: x => x.OrdInfoId,
                        principalSchema: "Outpatient",
                        principalTable: "OtpOrd",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_OtpPayRec_OtpPayWay_PayWayId",
                        column: x => x.PayWayId,
                        principalSchema: "Outpatient",
                        principalTable: "OtpPayWay",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_OtpOrdDetl_OrdInfoId",
                schema: "Outpatient",
                table: "OtpOrdDetl",
                column: "OrdInfoId");

            migrationBuilder.CreateIndex(
                name: "IX_OtpOrdFeeDetl_OrdInfoId",
                schema: "Outpatient",
                table: "OtpOrdFeeDetl",
                column: "OrdInfoId");

            migrationBuilder.CreateIndex(
                name: "IX_OtpPayRec_OrdInfoId",
                schema: "Outpatient",
                table: "OtpPayRec",
                column: "OrdInfoId");

            migrationBuilder.CreateIndex(
                name: "IX_OtpPayRec_PayWayId",
                schema: "Outpatient",
                table: "OtpPayRec",
                column: "PayWayId");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "OtpOrdDetl",
                schema: "Outpatient");

            migrationBuilder.DropTable(
                name: "OtpOrdFeeDetl",
                schema: "Outpatient");

            migrationBuilder.DropTable(
                name: "OtpPayRec",
                schema: "Outpatient");

            migrationBuilder.DropTable(
                name: "OtpOrd",
                schema: "Outpatient");

            migrationBuilder.DropTable(
                name: "OtpPayWay",
                schema: "Outpatient");
        }
    }
}
